package com.haowu.product.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.haowu.common.core.domain.R;
import com.haowu.common.core.validate.AddGroup;
import com.haowu.common.core.validate.EditGroup;
import com.haowu.common.core.web.controller.BaseController;
import com.haowu.common.excel.utils.ExcelUtil;
import com.haowu.common.log.annotation.Log;
import com.haowu.common.log.enums.BusinessType;
import com.haowu.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.haowu.product.domain.vo.HwServiceSkuVo;
import com.haowu.product.domain.bo.HwServiceSkuBo;
import com.haowu.product.service.IHwAppServiceSkuService;
import com.haowu.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 服务项目sku控制器
 * 前端访问路由地址为:/product/hwAppServiceSku
 *
 * @author lky
 * @date 2023-02-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hwAppServiceSku")
public class HwAppServiceSkuController extends BaseController {

    private final IHwAppServiceSkuService iHwAppServiceSkuService;

    /**
     * 查询服务项目sku列表
     */
    @SaCheckPermission("product:hwAppServiceSku:list")
    @GetMapping("/list")
    public TableDataInfo<HwServiceSkuVo> list(HwServiceSkuBo bo, PageQuery pageQuery) {
        return iHwAppServiceSkuService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务项目sku列表
     */
    @SaCheckPermission("product:hwAppServiceSku:export")
    @Log(title = "服务项目sku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HwServiceSkuBo bo, HttpServletResponse response) {
        List<HwServiceSkuVo> list = iHwAppServiceSkuService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务项目sku", HwServiceSkuVo.class, response);
    }

    /**
     * 获取服务项目sku详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("product:hwAppServiceSku:query")
    @GetMapping("/{id}")
    public R<HwServiceSkuVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iHwAppServiceSkuService.queryById(id));
    }

    /**
     * 新增服务项目sku
     */
    @SaCheckPermission("product:hwAppServiceSku:add")
    @Log(title = "服务项目sku", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HwServiceSkuBo bo) {
        return toAjax(iHwAppServiceSkuService.insertByBo(bo));
    }

    /**
     * 修改服务项目sku
     */
    @SaCheckPermission("product:hwAppServiceSku:edit")
    @Log(title = "服务项目sku", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HwServiceSkuBo bo) {
        return toAjax(iHwAppServiceSkuService.updateByBo(bo));
    }

    /**
     * 删除服务项目sku
     *
     * @param ids 主键串
     */
    @SaCheckPermission("product:hwAppServiceSku:remove")
    @Log(title = "服务项目sku", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iHwAppServiceSkuService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
